from db import db
import datetime

class Question(db.Model):
    __tablename__ = 'question'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(255), nullable=False)
    content = db.Column(db.String(255), nullable=False)
    file_url = db.Column(db.String(255), nullable=False)
    publisher = db.Column(db.String(255), nullable=False)
    create_time = db.Column(db.DateTime, default=datetime.datetime.now)
    tag = db.Column(db.String(255), nullable=False)
    view = db.Column(db.Integer, nullable=False)
    reply = db.Column(db.Integer, nullable=False)

    def __init__(self, title, content, file_url, publisher, tag):
        self.title = title
        self.content = content
        self.file_url = file_url
        self.publisher = publisher
        self.tag = tag
        self.view = 0
        self.reply = 0

    def to_dict(self):
        return {
            'id': self.id,
            'title': self.title,
            'content': self.content,
            'fileUrl': self.file_url,
            'publisher': self.publisher,
            'createTime': self.create_time,
            'tag': self.tag,
            'view': self.view,
            'reply': self.reply
        }